--Abstract Factory
--[[
    抽象工厂：（创建型）
    作用：工厂方法的扩展，同一工厂可以生产一系列对象
--]]

require 'Class'

IEnemy = Class()  --敌人
Enemy_Lv1 = Class(IEnemy)
Enemy_Lv1.Init = function(self)
    print(string.format('生产敌人：%s',self.Name))
end
Enemy_Boss = Class(IEnemy)
Enemy_Boss.Init = function(self)
    print(string.format('生产敌人：%s',self.Name))
end

IWeapon = Class()  --武器
Weapon_Lv1 = Class(IWeapon)
Weapon_Lv1.Init = function(self)
    print(string.format('生产武器：%s',self.Name))
end
Weapon_Max = Class(IWeapon)
Weapon_Max.Init = function(self)
    print(string.format('生产武器：%s',self.Name))
end

--工厂接口
IFactory = Class()
--敌人工厂
Enemy_Lv1_Factory = Class(IFactory)
Enemy_Lv1_Factory.Create = function(self,params)
    enemy = Enemy_Lv1:New(params)
    enemy:Init()
    return enemy
end
Enemy_Boss_Factory = Class(IEnemyFactory)
Enemy_Boss_Factory.Create = function(self,params)
    enemy = Enemy_Boss:New(params)
    enemy:Init()
    return enemy
end
--武器工厂
Weapon_Lv1_Factory = Class(IFactory)
Weapon_Lv1_Factory.Create = function(self,params)
    weapon = Weapon_Lv1:New(params)
    weapon:Init()
    return weapon
end
Weapon_Max_Factory = Class(IFactory)
Weapon_Max_Factory.Create = function(self,params)
    weapon = Weapon_Max:New(params)
    weapon:Init()
    return weapon
end

--------Main--------
function main()
    enemy_Lv1_Factory = Enemy_Lv1_Factory:New()
    enemy_Lv1 = enemy_Lv1_Factory:Create({Name = '等级为1的小兵'})
    enemy_Boss_Factory = Enemy_Boss_Factory:New()
    enemy_Boss = enemy_Boss_Factory:Create({Name = 'Boss'})
    weapon_Lv1_Factory = Weapon_Lv1_Factory:New()
    weapon_Lv1 = weapon_Lv1_Factory:Create({Name = '等级为1的武器'})
    weapon_Max_Factory = Weapon_Max_Factory:New()
    weapon_Max = weapon_Max_Factory:Create({Name = '最高等级的武器'})
end

main()